package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.annotation.MyLog;
import com.woniuxy.entity.Fix;
import com.woniuxy.service.fix.FixService;
import com.woniuxy.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class FixController {
    @Autowired
    private FixService fixService;


    @PostMapping("fix/findAll")
    public ResultVo findAll(@RequestBody Map<String,String> map){
        String page = map.remove("page");
        String size = map.remove("size");
        PageInfo<Fix> all = fixService.findAll(Integer.valueOf(page), Integer.valueOf(size));
        return ResultVo.success(all);
    }
    @MyLog("修改维修记录")
    @PostMapping("fix/update")
    public ResultVo update(@RequestBody Fix fix){
        int rows = fixService.update(fix);
        return rows > 0 ? ResultVo.success() : ResultVo.failure();
    }

    @MyLog("删除维修记录")
    @PostMapping("fix/delete")
    public ResultVo delete(@RequestBody String fId){
        int rows = fixService.delete(Integer.valueOf(fId));
        return rows > 0 ? ResultVo.success() : ResultVo.failure();
    }
}
